<?php
class FooterScriptWidget  extends CWidget{
    
	//输出字符串
	private $out = '';
    
    private $controller= '';
    
	private $action= '';

	private $module = '';

	public function init(){
		$this->controller = Yii::app()->controller->id;  
		$this->action = Yii::app()->controller->action->id;
		$this->module = isset(Yii::app()->controller->module->id) ? Yii::app()->controller->module->id : '';
		
	}

	public function run(){
        $this->generateFooterScript();
		echo $this->out;
	}
    
    public function configNavItem(){
        $item = array(
            array('title'=>'首页','url'=>Yii::app()->createUrl('site/index'),'active'=>($this->controller == 'site' ? 'active' : '')),
            array('title'=>'资源','url'=>Yii::app()->createUrl('resource/index'),'active'=>($this->controller == 'resource' ? 'active' : '')),  
        );
        return $item;
    }
    
    public function generateFooterScript(){
        $baseScript = Yii::app()->request->baseUrl;
        
        $viewScript = '';
        if($this->controller == 'site' && $this->action=='view'){
            $viewScript .= '<script src="'.$baseScript.'/syntaxhighlighter/scripts/shCore.js"></script>'."\n";
            $viewScript .= '<script src="'.$baseScript.'/syntaxhighlighter/scripts/shAutoloader.js"></script>'."\n";
            $viewScript .= '<script src="'.$baseScript.'/js/script-view.js"></script>'."\n";
        }
        
        //搜索
        $searchScript = '';
        if($this->controller == 'site' && $this->action == 'search'){
            $searchScript = '<script src="'.$baseScript.'/js/jquery.highlight-4.closure.js"></script>'."\n";
        }

		if($this->module == 'admin' && $this->controller == 'default' && $this->action == 'index'){
			 $adminProbeScript = '<script src="'.$baseScript.'/js/script-admin-probe.js"></script>'."\n";

		}else{
			 $adminProbeScript = '';

        }

        if($this->module == 'admin'){
            $baiduAppScript = '';
        }else{
            $baiduAppScript = '<script charset="gbk" src="http://www.baidu.com/js/opensug.js"></script>'."\n";
        }
		
		
		//<script src="{$baseScript}/js/jquery.placeholder.js"></script>\n
		
		
        if($this->module == 'admin'){
            $weiboScript = '';
        }else{
            $weiboScript = '<script src="http://tjs.sjs.sinajs.cn/open/api/js/wb.js" type="text/javascript" charset="utf-8"></script>'."\n";
        }
		
		//是否调用jquery
		if($this->module == 'admin' && in_array($this->action,array('create','update'))){
			$jquery_script = '';
		}else{
			$jquery_script = "<script src='{$baseScript}/js/jquery-1.8.3.min.js'></script>\n";
		}
		
        
        $this->out .= <<<OUT
{$jquery_script}
<script src="{$baseScript}/js/jquery.placeholder.js"></script>
<script src="{$baseScript}/js/jquery.stacktable.js"></script>
<script src="{$baseScript}/js/jquery.tagsinput.js"></script>
<script src="{$baseScript}/js/jquery.scrollUp.min.js"></script>
<script src="{$baseScript}/js/bootstrap.min.js"></script>
<script src="{$baseScript}/js/bootstrap-select.js"></script>
<script src="{$baseScript}/js/bootstrap-switch.js"></script>
<script src="{$baseScript}/js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="{$baseScript}/js/flatui-checkbox.js"></script>
<script src="{$baseScript}/js/flatui-radio.js"></script>
<script src="{$baseScript}/fancyBox/source/jquery.fancybox.pack.js"></script>
<script src="{$baseScript}/js/application.js"></script>
<script src="{$baseScript}/js/script.js"></script>
{$viewScript}
{$adminProbeScript}
{$baiduAppScript}
{$weiboScript}
{$searchScript}
OUT;
    }
}


